#include<bits/stdc++.h>
#define int long long
using namespace std;
inline int read()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+(ch^48);ch=getchar();}
	return x*f;
}
struct node{
	int d,v,a;
}c[100005];
int a[100005],vis[100005],di[100005];
struct Node{
	int l,r;
};
vector<Node> bd;
bool cmp(Node x,Node y)
{
	return x.l<y.l || (x.l==y.l && x.r<y.r);
}
signed main()
{
	//
	//freopen     
	//freopen
	//freopen
	//freopen
	//freopen
	//freopen luogu uid 772909
	freopen("detect.in","r",stdin);
	freopen("detect.out","w",stdout);
	int T=read();
	while(T--)
	{
		bd.clear();
		int n=read(),m=read(),L=read(),v=read();
		L=L;
		a[m+1]=LLONG_MAX;
		a[m+2]=LLONG_MAX;
		a[m+3]=LLONG_MAX;
		a[m+4]=LLONG_MAX;
		a[m+5]=LLONG_MAX;
		for(int i=1;i<=n;i++)
		{
			c[i].d=read();
			c[i].v=read();
			c[i].a=read();
		}
		for(int i=1;i<=m;i++) a[i]=read();
		for(int i=1;i<=n;i++)
		{
			if(c[i].a==0)
			{
				if(c[i].v<=v) continue;
				int l=0,r=m+5;
				while(l+1<r)
				{
					int mid=(l+r)>>1;
					if(c[i].d<=a[mid]) r=mid;
					else l=mid;
				}
				if(r<=m)bd.push_back(Node{r,m});
			}
			else if(c[i].a>0)
			{
				if(c[i].v>v)
				{
					int l=0,r=m+5;
					while(l+1<r)
					{
						int mid=(l+r)>>1;
						if(c[i].d<=a[mid]) r=mid;
						else l=mid;
					}
					if(r<=m)bd.push_back(Node{r,m});
				}
				else
				{
					int s=(v*v-c[i].v*c[i].v)/(2*c[i].a)+1;
					int l=0,r=m+5;
					while(l+1<r)
					{
						int mid=(l+r)>>1;
						if(c[i].d+s<=a[mid]) r=mid;
						else l=mid;
					}
					if(r<=m)bd.push_back(Node{r,m});
				}
			}
			else
			{
				if(c[i].v<=v)continue;
				int s=(v*v-c[i].v*c[i].v)/(2*c[i].a)-(((v*v-c[i].v*c[i].v)%(2*c[i].a)==0)?1:0);
				int l=0,r=m+5;
				while(l+1<r)
				{
					int mid=(l+r)>>1;
					if(c[i].d>a[mid]) l=mid;
					else r=mid;
				}
				int t=r;
				l=0,r=m+5;
				while(l+1<r)
				{
					int mid=(l+r)>>1;
					if(c[i].d+s>=a[mid]) l=mid;
					else r=mid;
				}
				if(t<=l) bd.push_back(Node{t,l});
			}
		}
		printf("%lld ",(int)bd.size());
		sort(bd.begin(),bd.end(),cmp);
		int ans=0,Ll=1,R=n;
		for(int i=0;i<(int)bd.size();i++)
		{
			Ll=max(Ll,bd[i].l);
			R=min(R,bd[i].r);
			if(Ll>R)
			{
				ans++;
				Ll=bd[i].l;
				R=bd[i].r;
			}
		}
		if(bd.size()==0)printf("%lld\n",m);
		else
		{
			ans++;
			printf("%lld\n",m-ans);
		}
	}
	return 0;
}
